<template>
    <div class="order-list-container">
        <div class="olc-head">
            <span>订单编号：{{ ibase.number }}</span>
            <span>{{ buildStateText }}</span>
        </div>
        <order-list-item :ibase="ibase" :dataset="dataset" type="shop" />
        <div class="olc-price" v-if="ibase.amount">
            <p>预估价格：<span>￥</span><span>{{ parseFloat(ibase.amount).toFixed(2) }}</span></p>
            <p v-if="ibase.protect==1" class="tip-footer">(价格保护已开启)</p>
        </div>
        <div :class="{'olc-footer': !stylePlan, 'olc-footer-qun': stylePlan}">
            <van-button size="small" @click="eventClickOrderDetail" type="primary" class="normal-diy-button" round>{{ buildHostButtonText }}</van-button>
        </div>
    </div>
</template>

<script>
    import {Button,Dialog} from 'vant';

    import OrderListItem from './normal-list-base.vue';

    export default {
        components: {
            [Button.name]: Button,
            OrderListItem
        },
        props: ['textType', 'ibase', 'dataset'],
        computed: {
            buildStateText() {
                var stateText = '';
                switch (this.textType) {
                    case 'confirm':
                        stateText = '待确认';
                        break;
                    case 'un-confirm':
                        stateText = '已确认';
                        break;
                }
                return stateText;
            },
            buildHostButtonText() {
                var buttonText = '';
                switch (this.textType) {
                    case 'confirm':
                        buttonText = '确认';
                        break;
                    case 'un-confirm':
                        buttonText = '查看详情';
                        break;
                }
                return buttonText;
            },
            stylePlan() {
                return this.ibase.style ? true : false;
            }
        },
        mounted() {
        },
        methods: {
            eventClickOrderDetail() {
                this.$router.push({
                    path:'/shop/order-details',
                    query:{
                        ordernumber:this.ibase.number
                    }
                })
            },
            eventClickOrderConfirm(){
                var url = '/api/home/order/confirm';
                var param = {
                    ordernumber:this.ibase.number,
                    token:this.$store.state.options.user.token
                };
                this.$util.postRequestInterface(url,param,(res)=>{
                    if (res.code==200){
                        Dialog.alert({
                            title:'提示',
                            message:res.msg
                        }).then(()=>{
                            this.$router.go(-1)
                        })
                    }
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .order-list-container {
        border-bottom: 0.4rem solid #EEEEEE;

        .olc-head {
            margin-bottom: 1rem;
            padding: 0.5rem 0rem 0.8rem;
            border-bottom: 0.1rem solid #EEEEEE;
            display: flex;
            justify-content: space-between;

            span:first-child {
                font-size: 1.3rem;
                color: #999999;
            }

            span:last-child {
                font-size: 1.3rem;
                color: #00CC00;
            }
        }

        .olc-price {
            padding: 1rem 0rem 0rem;
            text-align: right;

            p:first-child {
                font-size: 1.4rem;
                color: #999999;

                span {
                    color: #FF0101;
                }

                span:first-child {
                    font-size: 1.4rem;
                }

                span:last-child {
                    font-size: 1.9rem;
                }
            }

            .tip-footer {
                font-size: 1.3rem;
                color: #FF9000;
            }
        }

        .olc-footer, .olc-footer-qun {
            margin-top: 1rem;
            padding: 1rem 0rem;
            border-top: 0.1rem solid #EEEEEE;
            display: flex;
            flex-direction: row-reverse;
        }

        .olc-footer-qun {
            margin: 0rem;
            padding-top: 0.5rem;
            border: none;
        }
    }

    .order-assist-button {
        background-color: #ffffff;
        color: #00CC00 !important;
        padding-left: 2rem !important;
        padding-right: 2rem !important;
        font-size: 1.3rem;
        margin-right: 0.8rem;
    }
</style>
